﻿; (function ($, window, document, undefined) {
    var myApp = window.myApp;
    var controller = myApp.controllers.controller;
    var view = myApp.views.view;
    
    myApp.controllers.productsController = aramza.define(function () {
        var ds = aramza.resolve(myApp.dataService);
        
        return {
            index: function () {
                var model = ds.products;

                return this.view(model);
            },
            edit: function (model) {
                return this.view(model);
            }
        };
    }, controller);
    
    myApp.views.products = {};

    var writer = "@helper writeProduct(product) { <span>product name is [@product.name]</span> <a id='edit' href='#products/edit/@product.id'>Edit</a><br/> } ";
    
    myApp.views.products.index = writer + "@for (var i = 0; i < model.length; i++) { @writeProduct(model[i]) }";

    myApp.views.products.edit = aramza.define(function () {
        return {
            template: "edit product id @model.id <a id='back' href='#products'>Back</a>",
            init: function () {
                $("#back").click(function () {
                    alert('going back');
                });
            },
            destroy: function () {
                alert("view destroyed");
            }
        };
    }, view);
})(jQuery, window, document);
